package com.webapp.model;

import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Post{
	
	private int postId;
	private String date;
	private String content;
	private int commentCount;
	private int circle;
	private int author;
	
	public Post(int circleId, int authorId, String textContent){
		postId = new Double( Math.random() * 100000 ).intValue();
		content = textContent;
		commentCount = 0;
		circle = circleId;
		author = authorId;
		
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Calendar cal = Calendar.getInstance();
		date = dateFormat.format(cal.getTime());
	}
	
	public Post(int circleId, int authorId, String textContent, String dater, int comCount, int post){
		postId = post;
		date = dater;
		content = textContent;
		commentCount = comCount;
		circle = circleId;
		author = authorId;
	}
	
	public Post(int postId, int circleId, int authorId, String textContent){
		this.postId = postId;
		System.out.println("id " + postId);
		content = textContent;
		PostModel pm = new PostModel();
		commentCount = pm.getPost(postId).getCommentCount();
		circle = circleId;
		author = authorId;
		
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Calendar cal = Calendar.getInstance();
		date = dateFormat.format(cal.getTime());
	}
	
	
	public int getPostId(){return this.postId;}
	public String getDate(){return this.date;}
	public String getContent(){return this.content;}
	public int getCommentCount(){return this.commentCount;}
	public int getCircle(){return this.circle;}
	public int getAuthor(){return this.author;}
	
	public void setPostId(int newId){this.postId = newId;}
	public void setDate(String newDate){this.date = newDate;}
	public void setContent(String newContent){this.content = newContent;}
	public void setCommentCount(int count){this.commentCount = count;}
	public void setCircle(int newCircle){this.circle = newCircle;}
	public void setAuthor(int newAuthor){this.author = newAuthor;}
	
	public void addNewComment(){commentCount++;}
	public void removeComment(){commentCount--;}
	

}
